<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateChatTable extends Migration
{
    public function up()
    {
        //好友表
        Schema::create('chat_friend', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('user_id',20)->comment('用户名ID');
            $table->string('friend_id',20)->comment('好友ID');
            $table->timestamps();
        });
	    //群组表
	    Schema::create('chat_group', function (Blueprint $table) {
		    $table->increments('id');
		    $table->string('group_name',20)->unique()->comment('群名称');
		    $table->string('group_admin_id',20)->comment('群管理');
		    $table->string('group_avatar')->nullable()->comment('群头像');
		    $table->unsignedSmallInteger('group_upper_limit')->default(2000)->comment('群人员上限 默认=2000');
		    $table->timestamps();
	    });
	    //群用户
	    Schema::create('chat_group_user', function (Blueprint $table) {
		    $table->increments('id');
		    $table->string('group_id',20)->comment('群ID');
		    $table->string('user_id',20)->comment('用户ID');
		    $table->string('client_id',20)->default('')->comment('客户端ID');
		    $table->timestamps();
	    });
	    //好友信息
	    Schema::create('chat_friend_message', function (Blueprint $table) {
		    $table->bigIncrements('id');
		    $table->string('user_id',20)->comment('发送ID');
		    $table->string('friend_id',20)->comment('接受ID');
		    $table->text('message')->comment('内容');
		    $table->boolean('read')->comment('是否已读');
		    $table->timestamp('read_time')->comment('已读时间');
		    $table->timestamps();
	    });
	    //群信息
	    Schema::create('chat_group_message', function (Blueprint $table) {
		    $table->bigIncrements('id');
		    $table->string('group_id',20)->comment('发送ID');
		    $table->string('user_id',20)->comment('接受ID');
		    $table->text('message')->comment('内容');
		    $table->timestamps();
	    });
	    //系统信息
	    Schema::create('chat_system_message', function (Blueprint $table) {
		    $table->bigIncrements('id');
		    $table->string('user_id',20)->comment('用户ID');
		    $table->unsignedTinyInteger('type')->default(0)->comment('类型 系统信息0,好友申请1,进群申请2');
		    $table->string('target_id')->default(0)->comment('目标ID  好友ID,群ID');
		    $table->text('message')->comment('消息内容');
		    $table->boolean('read')->default(false)-> comment('已读 ,默认 false');
		    $table->boolean('action')->default(false)-> comment('是否已操作 默认false');
		    $table->timestamps();
	    });
    }

    public function down()
    {
        Schema::dropIfExists('chat_friend');
        Schema::dropIfExists('chat_group');
        Schema::dropIfExists('chat_group_user');
        Schema::dropIfExists('chat_friend_message');
        Schema::dropIfExists('chat_group_message');
        Schema::dropIfExists('chat_system_message');
    }
}
